<template>
	<view>
		<view class=" u-p-r-30 u-p-l-30 u-m-t-20" >
			<u-search placeholder="请输入作业单号或作业内容搜索" :clearabled="true" v-model="keyword" border-color="#606266" @custom="search" @search="search"></u-search>
		</view>
		<u-card padding="16" v-for="item in dataList" :key="item.id">
			<view class="" slot="head">
				<view class="wrap">
					<u-row>
						<u-col span="10">
							<view class="title">
								<span>作业内容：</span><span>{{item.v1}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
			<view class="" slot="body">
				<view class="wrap">
					<u-row >
						<u-col span="5">
							<view class="u-line-1 u-m-t-10 jinxingzhong" v-if="item.status == '作业中'">
								<span>状态：</span><span>{{item.status}}</span>
							</view>
							<view class="u-line-1 u-m-t-10 yiwancheng" v-else>
								<span>状态：</span><span>{{item.status}}</span>
							</view>
						</u-col>
						<u-col span="7">
							<view class="u-line-1 u-m-t-10">
								<span>项目部：</span><span>{{item.v2}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
				<view class="wrap">
					<u-row >
						<u-col span="6">
							<view class="u-line-1 u-m-t-10">
								<span>单号：</span><span>{{item.orderNumber}}</span>
							</view>
						</u-col>
						<u-col span="6">
							<view class="u-line-1 u-m-t-10">
								<span>作业日期：</span><span>{{item.v4}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
				<view class="wrap">
					<u-row >
						<u-col span="6">
							<view class="u-line-1 u-m-t-10">
								<span>作业类型：</span><span>{{item.v3}}</span>
							</view>
						</u-col>
						<u-col span="6">
							<view class="u-line-1 u-m-t-10">
								<span>类别：</span><span>{{item.v6}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
				<view class="wrap">
					<u-row >
						<u-col span="6">
							<view class="u-line-1 u-m-t-10">
								<span>明细：</span><span>{{item.detaileds}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
				<view class="wrap">
					<u-row >
						<u-col span="6">
							<view class="u-line-1 u-m-t-10">
								<span>车型：</span><span>{{item.v5}}</span>
							</view>
						</u-col>
						<u-col span="6" v-if="item.settlementMode == '体积'">
							<view class="u-line-1 u-m-t-10">
								<span>体积：</span><span>{{item.volume}}</span>
							</view>
						</u-col>
						<u-col span="6" v-if="item.settlementMode == '数量'">
							<view class="u-line-1 u-m-t-10">
								<span>数量：</span><span>{{item.nums}}</span>
							</view>
						</u-col>
						<u-col span="6" v-if="item.settlementMode == '重量'">
							<view class="u-line-1 u-m-t-10">
								<span>重量(吨)：</span><span>{{item.weights}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
				<view class="wrap">
					<u-row >
						<u-col span="6">
							<view class="u-line-1 u-m-t-10">
								<span>工时：</span><span>{{item.hours}}</span>
							</view>
						</u-col>
						<u-col span="6">
							<view class="u-line-1 u-m-t-10">
								<span>作业人员：</span><span>{{item.userName}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
				<view class="wrap">
					<u-row >
						<u-col span="6">
							<view class="u-line-1 u-m-t-10">
								<span>开始时间：</span><span>{{item.startTime.substring(5, 16)}}</span>
							</view>
						</u-col>
						<u-col span="6">
							<view class="u-line-1 u-m-t-10">
								<span>结束时间：</span><span>{{item.endTime.substring(5, 16)}}</span>
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
		</u-card>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				keyword:'',
				dataList: [],
			}
		},
		onShow() {
			this.refresh()
		},
		onPullDownRefresh() {
			this.refresh()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			uni.showLoading({
				title: '加载中'
			})
			if (this.hasMore) {
				this.pageNo++ 
				setTimeout(() => {
					this.loadOrder({
						condition: this.keyword
					}).then(res => {})
					uni.hideLoading()
				}, 500)
			} else {
				setTimeout(() => {
					uni.hideLoading()
					uni.showToast({
						icon: 'none',
						title: '已经到低了哦',
						duration: 2000
					});
				}, 500)
			}
		},
		methods: {
			refresh(){
				this.pageNo = 1
				this.hasMore = true
				this.loadOrder({
					condition: this.keyword
				}).then(res => {
				})
			},
			loadOrder(param = {}) {
				return new Promise((resolve, reject) => {
					param = Object.assign(param, {
						page: this.pageNo,
						limit: 10
					})
					this.$http.post('/rest/taskDetailed/melist',{
					},{
						params: param,
						header: {
							'Authorization' :uni.getStorageSync('token'),
						}
					}).then(res => {
						if (this.pageNo == 1) {
							this.dataList = res.data.data
						} else {
							this.dataList = this.dataList.concat(res.data.data)
						}
						this.orderCount = res.data.count
						this.hasMore = this.pageNo * 10 < res.data.count
						resolve(res)
					})
				})
			},
			search(e){
				uni.showLoading({
					title: '加载中'
				})
				this.refresh()
				setTimeout(() => {
					uni.hideLoading()
				}, 500)
			},
		}
	}
</script>
